package ch.zbw.sysventory.server.model;

import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name = "computerscanresult")
public class ComputerScanResult extends BaseEntity implements Comparable<ComputerScanResult> {

	@Id
	@GeneratedValue
	private Long id;
	@ManyToOne(optional = false)
	private Computer computer;
	@ManyToOne
	private ComputerScan computerScan;
	@Temporal(TemporalType.TIMESTAMP)
	private Date timeStamp;
	private String operatingSystem;
	private String cpu;
	private String sid;
	private String computerName;
	private String ram;
	private String computerType;
	private String scanIpAddress;
	@ManyToMany
	@LazyCollection(LazyCollectionOption.FALSE)
	private List<Software> softwareList;
	@ManyToMany
	@LazyCollection(LazyCollectionOption.FALSE)
	private List<Printer> printerList;
	@OrderBy("adapterWithScanIp DESC" )
	@ManyToMany
	@LazyCollection(LazyCollectionOption.FALSE)
	private List<NetworkAdapter> networkAdapterList;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getScanIpAddress() {
		return scanIpAddress;
	}

	public void setScanIpAddress(String scanIpAddress) {
		this.scanIpAddress = scanIpAddress;
	}

	public Computer getComputer() {
		return computer;
	}

	public void setComputer(Computer computer) {
		this.computer = computer;
	}

	public ComputerScan getComputerScan() {
		return computerScan;
	}

	public void setComputerScan(ComputerScan computerScan) {
		this.computerScan = computerScan;
	}

	public Date getTimeStamp() {
		return timeStamp;
	}

	public void setTimeStamp(Date timeStamp) {
		this.timeStamp = timeStamp;
	}

	public String getOperatingSystem() {
		return operatingSystem;
	}

	public void setOperatingSystem(String operatingSystem) {
		this.operatingSystem = operatingSystem;
	}

	public String getCpu() {
		return cpu;
	}

	public void setCpu(String cpu) {
		this.cpu = cpu;
	}

	public String getSid() {
		return sid;
	}

	public void setSid(String sid) {
		this.sid = sid;
	}

	public String getComputerName() {
		return computerName;
	}

	public void setComputerName(String computerName) {
		this.computerName = computerName;
	}

	public String getRam() {
		return ram;
	}

	public void setRam(String ram) {
		this.ram = ram;
	}

	public String getComputerType() {
		return computerType;
	}

	public void setComputerType(String computerType) {
		this.computerType = computerType;
	}

	public List<Software> getSoftwareList() {
		return softwareList;
	}

	public void setSoftwareList(List<Software> softwareList) {
		this.softwareList = softwareList;
	}

	public List<Printer> getPrinterList() {
		return printerList;
	}

	public void setPrinterList(List<Printer> printerList) {
		this.printerList = printerList;
	}

	public List<NetworkAdapter> getNetworkAdapterList() {
		return networkAdapterList;
	}

	public void setNetworkAdapterList(List<NetworkAdapter> networkAdapterList) {
		this.networkAdapterList = networkAdapterList;
	}

	@Override
	public int compareTo(ComputerScanResult computerScanResult) {
		if (this.timeStamp != null && computerScanResult.getTimeStamp() != null)
			return (this.timeStamp.compareTo(computerScanResult.getTimeStamp()) * (-1));
		return 0;
	}

}
